package com.jeedroid.weibo;

import java.io.UnsupportedEncodingException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.Map;

import com.jeedroid.weibo.oauth.OAuth;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
public class LogoActivity extends Activity {
    /** Called when the activity is first created. */
	private ImageView welcomeView;
	private OAuth oauth;
	private String req_yes_request_token_url;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.logo);
        showAnimation();
    }
    
    private void showAnimation()
    {
    	welcomeView=(ImageView)findViewById(R.id.welcomeAnmiId);
    	Animation animation=AnimationUtils.loadAnimation(this, R.anim.alpha);
    	welcomeView.setAnimation(animation);
    	
    	animation.setAnimationListener(new AnimationListener()
		{
			@Override
			public void onAnimationStart(Animation animation)
			{
				//获取未授权的request_token
			   try
			{
				String oauth_token="";
				String notRequestToken=OAuth.getNotRequestToken();
				Map<String,String> map=OAuth.getOauthToken(notRequestToken);
				oauth_token=map.get("oauth_token");
				//构造请求用户授权的request_token的url
				String url="https://open.t.qq.com/cgi-bin/authorize";
				StringBuilder stringBuilder=new StringBuilder();
				stringBuilder.append(url);
				stringBuilder.append("?");
				stringBuilder.append("oauth_token="+oauth_token);
				req_yes_request_token_url=stringBuilder.toString();
			} catch (InvalidKeyException e)
			{
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (NoSuchAlgorithmException e)
			{
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (UnsupportedEncodingException e)
			{
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			}
			@Override
			public void onAnimationRepeat(Animation animation)
			{
			}
			@Override
			public void onAnimationEnd(Animation animation)
			{
				 Intent intent=new Intent(LogoActivity.this,LoginActivity.class);
				 intent.putExtra("req_yes_reqtoken_url", req_yes_request_token_url);
			     startActivity(intent);
			     finish();
			}
		});
    	
    	
    }
}